home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / net / AmiPOP116.lha / AmiPOP116 / source / pop.c < prev    next >
C/C++ Source or Header  |  1995-01-04  |  11KB  |  427 lines

  1. #include "pop.h"
  2.  
  3. struct Screen         *Scr = NULL;
  4. APTR                   VisualInfo = NULL;
  5. struct Window         *Project0Wnd = NULL;
  6. struct Gadget         *Project0GList = NULL;
  7. struct Menu           *Project0Menus = NULL;
  8. struct IntuiMessage    Project0Msg;
  9. struct Gadget         *Project0Gadgets[9];
  10. UWORD                  Project0Width = 418;
  11. UWORD                  Project0Height = 69;
  12. UBYTE                 *Project0Wdt = (UBYTE *)"AmiPOP Client";
  13. struct TextAttr       *Font, Attr;
  14. UWORD                  FontX, FontY;
  15. UWORD                  OffX, OffY;
  16.  
  17. ULONG __saveds __asm hidepass( register __a0 struct Hook*, register __a2 struct SGWork* ,register __a1 ULONG* );
  18.  
  19. struct Hook hookentry =
  20. {
  21.     {0},
  22.     hidepass,
  23.     0,
  24.     0,
  25. };
  26.  
  27. struct NewMenu Project0NewMenu[] = {
  28.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  29.     NM_ITEM, (STRPTR)"Hide", (STRPTR)"H", 0, 0L, (APTR)Project0MENU_HIDE,
  30.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  31.     NM_ITEM, (STRPTR)"About...", NULL, 0, 0L, (APTR)Project0MENU_ABOUT,
  32.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)Project0MENU_QUIT,
  33.     NM_END, NULL, NULL, 0, 0L, NULL };
  34.  
  35. static UWORD ComputeX( UWORD value )
  36. {
  37.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  38. }
  39.  
  40. static UWORD ComputeY( UWORD value )
  41. {
  42.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  43. }
  44.  
  45. static void ComputeFont( UWORD width, UWORD height )
  46. {
  47.     Font = &Attr;
  48.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  49.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  50.     FontX = Scr->RastPort.Font->tf_XSize;
  51.  
  52.     OffX = Scr->WBorLeft;
  53.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  54.  
  55.     if ( width && height ) {
  56.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  57.             goto UseTopaz;
  58.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  59.             goto UseTopaz;
  60.     }
  61.     return;
  62.  
  63. UseTopaz:
  64.     Font->ta_Name = (STRPTR)"topaz.font";
  65.     FontX = FontY = Font->ta_YSize = 8;
  66. }
  67.  
  68. int SetupScreen( void )
  69. {
  70.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  71.     {
  72.         if ( ! (Scr = LockPubScreen( NULL )))
  73.         {
  74.             return( 1L );
  75.         }
  76.     }
  77.  
  78.     ComputeFont( 0, 0 );
  79.  
  80.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  81.         return( 2L );
  82.  
  83.     return( 0L );
  84. }
  85.  
  86. void CloseDownScreen( void )
  87. {
  88.     if ( VisualInfo ) {
  89.         FreeVisualInfo( VisualInfo );
  90.         VisualInfo = NULL;
  91.     }
  92.  
  93.     if ( Scr        ) {
  94.         UnlockPubScreen( NULL, Scr );
  95.         Scr = NULL;
  96.     }
  97. }
  98.  
  99. void Project0Render( void )
  100. {
  101.     ComputeFont( Project0Width, Project0Height );
  102.  
  103.     DrawBevelBox( Project0Wnd->RPort, OffX + ComputeX( 0 ),
  104.                     OffY + ComputeY( 50 ),
  105.                     ComputeX( 417 ),
  106.                     ComputeY( 18 ),
  107.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  108. }
  109.  
  110. int HandleProject0IDCMP( void )
  111. {
  112.     struct IntuiMessage    *m;
  113.     struct MenuItem        *n;
  114.     int            (*func)( void );
  115.     BOOL            running = TRUE;
  116.  
  117.     while( (Project0Wnd) && (m = GT_GetIMsg( Project0Wnd->UserPort ) ) ) {
  118.  
  119.         CopyMem(( char * )m, ( char * )&Project0Msg, (long)sizeof( struct IntuiMessage ));
  120.  
  121.         GT_ReplyIMsg( m );
  122.  
  123.         switch ( Project0Msg.Class ) {
  124.  
  125.             case    IDCMP_REFRESHWINDOW:
  126.                 GT_BeginRefresh( Project0Wnd );
  127.                 Project0Render();
  128.                 GT_EndRefresh( Project0Wnd, TRUE );
  129.                 break;
  130.  
  131.             case    IDCMP_CLOSEWINDOW:
  132.                 running = Project0CloseWindow();
  133.                 break;
  134.  
  135.             case    IDCMP_VANILLAKEY:
  136.                 Project0VanillaKey();
  137.                 break;
  138.  
  139.             case    IDCMP_CHANGEWINDOW:
  140.                 Project0ChangeWindow();
  141.                 break;
  142.  
  143.             case    IDCMP_GADGETUP:
  144.                 func = ( int (*) (void ) )(( struct Gadget * )Project0Msg.IAddress )->UserData;
  145.                 func();
  146.                 break;
  147.  
  148.             case    IDCMP_MENUPICK:
  149.                 while ( (Project0Msg.Code != MENUNULL) && (Project0Wnd) )
  150.                 {
  151.                     n = ItemAddress( Project0Menus, Project0Msg.Code );
  152.                     func = (int (*) (void) )(GTMENUITEM_USERDATA(n));
  153.                     running= func();
  154.                     Project0Msg.Code = n->NextSelect;
  155.                 }
  156.                 break;
  157.         }
  158.     }
  159.     return( running );
  160. }
  161.  
  162. int OpenProject0Window( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD ww,wh;
  167.  
  168.     WORD zipsize[]={~0,~0,200,90};
  169.  
  170.     hookentry.h_SubEntry = (ULONG (*)() )password; /* Attempt to get hook working again */
  171.     memset(passfake,PASSCHAR,strlen(password)); /* Show initial string gadget condition */
  172.     passfake[strlen(password)]='\0';
  173.  
  174.     ComputeFont( Project0Width, Project0Height );
  175.  
  176.     ww = ComputeX( Project0Width );
  177.     wh = ComputeY( Project0Height );
  178.  
  179.     if (( winx + ww + OffX + Scr->WBorRight ) > Scr->Width ) winx = Scr->Width - ww;
  180.     if (( winy + wh + OffY + Scr->WBorBottom ) > Scr->Height ) winy = Scr->Height - wh;
  181.  
  182.     zipsize[2]=(WORD)(ww + OffX + Scr->WBorRight);
  183.     zipsize[3]=(WORD)(Scr->WBorTop + (Scr->Font->ta_YSize +1));
  184.  
  185.     if ( ! ( g = CreateContext( &Project0GList )))
  186.         return( 1L );
  187.  
  188. /* */
  189.  
  190.     ng.ng_VisualInfo = VisualInfo;
  191.     ng.ng_TextAttr   = Font;
  192.     ng.ng_LeftEdge    = OffX + ComputeX( 85 );
  193.     ng.ng_TopEdge    = OffY + ComputeY( 17 );
  194.     ng.ng_Width        = ComputeX( 114 );
  195.     ng.ng_Height    = ComputeY( 12 );
  196.     ng.ng_GadgetID    = GD_MYGAD_USER;
  197.     ng.ng_GadgetText= "_Username";
  198.     ng.ng_Flags        = PLACETEXT_LEFT;
  199.     ng.ng_UserData    = (APTR)MYGAD_USERClicked;
  200.  
  201.     Project0Gadgets[GD_MYGAD_USER]=g=    CreateGadget(STRING_KIND,g,&ng,
  202.                                         GTST_String,    username,
  203.                                         GTST_MaxChars,    SMALLSTRING-1,
  204.                                         GT_Underscore,    '_',
  205.                                         TAG_DONE);
  206. /* */
  207.  
  208.     ng.ng_LeftEdge    = OffX + ComputeX( 85 );
  209.     ng.ng_TopEdge    = OffY + ComputeY( 32 );
  210.     ng.ng_Width        = ComputeX( 114 );
  211.     ng.ng_Height    = ComputeY( 12 );
  212.     ng.ng_GadgetID    = GD_MYGAD_PASSWORD;
  213.     ng.ng_GadgetText= "Pass_word";
  214.     ng.ng_Flags        = PLACETEXT_LEFT;
  215.     ng.ng_UserData    = (APTR)MYGAD_PASSWORDClicked;
  216.  
  217.     Project0Gadgets[GD_MYGAD_PASSWORD]=g=    CreateGadget(STRING_KIND,g,&ng,
  218.                                         GTST_String,    passfake,
  219.                                         GTST_EditHook,    &hookentry,
  220.                                         GTST_MaxChars,    SMALLSTRING-1,
  221.                                         GT_Underscore,    '_',
  222.                                         TAG_DONE);
  223.  
  224. /* */
  225.  
  226.     ng.ng_LeftEdge    = OffX + ComputeX( 414 ) - 25;
  227.     ng.ng_TopEdge    = OffY + ComputeY( 32 );
  228.     ng.ng_Width        = ComputeX( 26 );
  229.     ng.ng_Height    = ComputeY( 11 );
  230.     ng.ng_GadgetID    = GD_MYGAD_DELETE;
  231.     ng.ng_GadgetText= "_Delete Messages?";
  232.     ng.ng_Flags        = PLACETEXT_LEFT;
  233.     ng.ng_UserData    = (APTR)MYGAD_DELETEClicked;
  234.  
  235.     Project0Gadgets[GD_MYGAD_DELETE]=g=    CreateGadget(CHECKBOX_KIND,g,&ng,
  236.                                         GTCB_Checked,    delmail,
  237.                                         GT_Underscore,    '_',
  238.                                         TAG_END);
  239.  
  240. /* */
  241.  
  242.     ng.ng_LeftEdge    = OffX + ComputeX( 300 );
  243.     ng.ng_TopEdge    = OffY + ComputeY( 2 );
  244.     ng.ng_Width        = ComputeX( 114 );
  245.     ng.ng_Height    = ComputeY( 12 );
  246.     ng.ng_GadgetID    = GD_MYGAD_MAILBOX;
  247.     ng.ng_GadgetText= "Mail _Box";
  248.     ng.ng_Flags        = PLACETEXT_LEFT;
  249.     ng.ng_UserData    = (APTR)MYGAD_MAILBOXClicked;
  250.  
  251.     Project0Gadgets[GD_MYGAD_MAILBOX]=g=    CreateGadget(STRING_KIND,g,&ng,
  252.                                         GTST_String,    mailbox,
  253.                                         GTST_MaxChars,    BIGSTRING-1,
  254.                                         GT_Underscore,    '_',
  255.                                         TAG_DONE);
  256.  
  257. /* */
  258.  
  259.     ng.ng_LeftEdge    = OffX + ComputeX( 329 );
  260.     ng.ng_TopEdge    = OffY + ComputeY( 53 );
  261.     ng.ng_Width        = ComputeX( 83 );
  262.     ng.ng_Height    = ComputeY( 11 );
  263.     ng.ng_GadgetID    = GD_MYGAD_BUTTON;
  264.     ng.ng_GadgetText= "Check _Now";
  265.     ng.ng_Flags        = PLACETEXT_IN;
  266.     ng.ng_UserData    = (APTR)MYGAD_BUTTONClicked;
  267.  
  268.     Project0Gadgets[GD_MYGAD_BUTTON]=g=    CreateGadget(BUTTON_KIND,g,&ng,
  269.                                         GT_Underscore,    '_',
  270.                                         TAG_DONE);
  271.  
  272. /* */
  273.  
  274.     ng.ng_LeftEdge    = OffX + ComputeX( 85 );
  275.     ng.ng_TopEdge    = OffY + ComputeY( 2 );
  276.     ng.ng_Width        = ComputeX( 114 );
  277.     ng.ng_Height    = ComputeY( 12 );
  278.     ng.ng_GadgetID    = GD_MYGAD_HOST;
  279.     ng.ng_GadgetText= "_POP Host";
  280.     ng.ng_Flags        = PLACETEXT_LEFT;
  281.     ng.ng_UserData    = (APTR)MYGAD_HOSTClicked;
  282.  
  283.     Project0Gadgets[GD_MYGAD_HOST]=g=    CreateGadget(STRING_KIND,g,&ng,
  284.                                         GTST_String,    pophost,
  285.                                         GTST_MaxChars,    BIGSTRING-1,
  286.                                         GT_Underscore,    '_',
  287.                                         TAG_DONE);
  288.  
  289. /* */
  290.  
  291.     ng.ng_LeftEdge    = OffX + ComputeX( 202 );
  292.     ng.ng_TopEdge    = OffY + ComputeY( 53 );
  293.     ng.ng_Width        = ComputeX( 39 );
  294.     ng.ng_Height    = ComputeY( 12 );
  295.     ng.ng_GadgetID    = GD_MYGAD_TIME;
  296.     ng.ng_GadgetText= "How _Often";
  297.     ng.ng_Flags        = PLACETEXT_RIGHT;
  298.     ng.ng_UserData    = (APTR)MYGAD_TIMEClicked;
  299.  
  300.     Project0Gadgets[GD_MYGAD_TIME]=g=    CreateGadget(INTEGER_KIND,g,&ng,
  301.                                         GTIN_Number,    timecheck,
  302.                                         GTIN_MaxChars,    3,
  303.                                         GT_Underscore,    '_',
  304.                                         GA_Disabled,    !checkper,
  305.                                         TAG_DONE);
  306.  
  307. /* */
  308.  
  309.     ng.ng_LeftEdge    = OffX + ComputeX( 11 );
  310.     ng.ng_TopEdge    = OffY + ComputeY( 54 );
  311.     ng.ng_Width        = ComputeX( 26 );
  312.     ng.ng_Height    = ComputeY( 11 );
  313.     ng.ng_GadgetID    = GD_MYGAD_CRONCHECK;
  314.     ng.ng_GadgetText= "_Check Periodically";
  315.     ng.ng_Flags        = PLACETEXT_RIGHT;
  316.     ng.ng_UserData    = (APTR)MYGAD_CRONCHECKClicked;
  317.  
  318.     Project0Gadgets[GD_MYGAD_CRONCHECK]=g=    CreateGadget(CHECKBOX_KIND,g,&ng,
  319.                                         GTCB_Checked,    checkper,
  320.                                         GT_Underscore,    '_',
  321.                                         TAG_DONE);
  322.  
  323. /* */
  324.  
  325.     ng.ng_LeftEdge    =  OffX + ComputeX( 414 ) - 25;
  326.     ng.ng_TopEdge    = OffY + ComputeY( 17 );
  327.     ng.ng_Width        = ComputeX( 26 );
  328.     ng.ng_Height    = ComputeY( 11 );
  329.     ng.ng_GadgetID    = GD_MYGAD_APPEND;
  330.     ng.ng_GadgetText= "_Append to MailBox?";
  331.     ng.ng_Flags        = PLACETEXT_LEFT;
  332.     ng.ng_UserData    = (APTR)MYGAD_APPENDClicked;
  333.  
  334.     Project0Gadgets[GD_MYGAD_APPEND]=g=    CreateGadget(CHECKBOX_KIND,g,&ng,
  335.                                         GT_Underscore,    '_',
  336.                                         GTCB_Checked,    appfile,
  337.                                         TAG_DONE);
  338.  
  339.     if ( ! ( Project0Menus = CreateMenus( Project0NewMenu, TAG_DONE )))
  340.         return( 3L );
  341.  
  342.     LayoutMenus( Project0Menus, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_DONE );
  343.  
  344.     if ( ! ( Project0Wnd = OpenWindowTags( NULL,
  345.                 WA_Left,    (UWORD)winx,
  346.                 WA_Top,        (UWORD)winy,
  347.                 WA_Width,    ww + OffX + Scr->WBorRight,
  348.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  349.                 WA_IDCMP,    STRINGIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|INTEGERIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_CHANGEWINDOW|IDCMP_REFRESHWINDOW,
  350.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  351.                 WA_Gadgets,    Project0GList,
  352.                 WA_Title,    Project0Wdt,
  353.                 WA_PubScreen,    Scr,
  354.                 WA_AutoAdjust,    TRUE,
  355.                 WA_NewLookMenus,TRUE,
  356.                 WA_Activate,    TRUE,
  357.                 WA_Zoom,    zipsize,
  358.                 TAG_DONE )))
  359.     return( 4L );
  360.  
  361.     SetMenuStrip( Project0Wnd, Project0Menus );
  362.     GT_RefreshWindow( Project0Wnd, NULL );
  363.  
  364.     Project0Render();
  365.  
  366.     return( 0L );
  367. }
  368.  
  369. void CloseProject0Window( void )
  370. {
  371.     if ( Project0Menus      ) {
  372.         ClearMenuStrip( Project0Wnd );
  373.         FreeMenus( Project0Menus );
  374.         Project0Menus = NULL;    }
  375.  
  376.     if ( Project0Wnd        ) {
  377.         CloseWindow( Project0Wnd );
  378.         Project0Wnd = NULL;
  379.     }
  380.  
  381.     if ( Project0GList      ) {
  382.         FreeGadgets( Project0GList );
  383.         Project0GList = NULL;
  384.     }
  385. }
  386.  
  387. /* Hook goodies */
  388.  
  389. ULONG __saveds __asm hidepass(register __a0 struct Hook *hook, register __a2 struct SGWork *sgw, register __a1 ULONG *msg)
  390. {
  391.     UBYTE *pass_ptr;
  392.  
  393.     pass_ptr = (STRPTR)hook->h_SubEntry;
  394.  
  395.     sgw->BufferPos = sgw->NumChars;
  396.  
  397.     if(*msg == SGH_KEY)
  398.     {
  399.         switch (sgw->EditOp)
  400.         {
  401.             case EO_INSERTCHAR:
  402.                 pass_ptr[sgw->BufferPos - 1] = sgw->WorkBuffer[sgw->BufferPos - 1];
  403.                 pass_ptr[sgw->BufferPos] = '\0';
  404.                 sgw->WorkBuffer[sgw->BufferPos - 1] = (UBYTE)PASSCHAR;
  405.                 break;
  406.  
  407.             case EO_DELBACKWARD:
  408.                 pass_ptr[sgw->BufferPos] = '\0';
  409.                 break;
  410.  
  411.             default:
  412.                 sgw->Actions &= ~SGA_USE;
  413.                 break;
  414.         }
  415.  
  416.         return (~0L);
  417.     }
  418.     if(*msg == SGH_CLICK)
  419.     {
  420.         sgw->BufferPos = sgw->NumChars;
  421.         return (~0L);
  422.     }
  423.  
  424.     return (0L);
  425. }
  426.  
  427.